package com.wuliming.gulimall.search.controller;

import com.wuliming.common.utils.R;
import com.wuliming.gulimall.search.service.SearchSaveService;
import com.wuliming.to.es.SkuEsModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/search/save")
public class SearchSaveController {

    @Autowired
    private SearchSaveService searchSaveService;

    @PostMapping("/saveProduct")
    public R saveProduct(@RequestBody List<SkuEsModel> list) {
        boolean b = false;
        try {
            b = searchSaveService.saveProduct(list);
        } catch (IOException e) {
            log.error("商品上架失败");
            return R.ok();
        }
        if (b) {
            log.info("商品上架完成");
            return R.ok();
        } else {
            log.error("商品上架失败");
            return R.error();
        }
    }


}
